package sockettest.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @author RJA
 * @version V1.0
 * @Title: sockettest.demo_1
 * @Description:
 * @date 2019/7/5 14:36
 */
public class SocketServer {
    public static void main(String[] args){
        EventLoopGroup bossGroup = new NioEventLoopGroup();//从客户端接收链接，但不作处理
        EventLoopGroup workerGroup = new NioEventLoopGroup();//处理链接后续的处理

        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();//轻松启动服务端代码
            serverBootstrap.group(bossGroup,workerGroup).channel(NioServerSocketChannel.class)
                    .childHandler(new SocketServerInitializer());
            ChannelFuture future = serverBootstrap.bind(8899).sync();
            future.channel().closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }

    }
}
